[#import "/framework/JGP.htm"  as JGP]
<!--
项目   jgp-cloud-parent
作者   LOUFEI [Gavin]
时间   2018/6/3
-->
[@JGP.head "Title"/]
[@JGP.body]
    <jgp-div _row="['40','90','*']" _runit="px">
        <div slot="1-1">
            <jgp-btn _size="small" _type="open" _fn="closeCallback"
                     _action="{'url':'/third/wx/wxConfigController/addUseFor','title':'创建用途',
                     'width':'500px','height':'660px'}">创建用途
            </jgp-btn>

        </div>
        <jgp-query slot="2-1" _id="queryUseForForm" _label_width="60px"
                   _action="/third/wx/wxConfigApiController/queryUseFor"
                   _target="useForGrid">
            <jgp-form-group _title="查询">
                <jgp-text _name="name" _col="6" _placeholder="用途"></jgp-text>
            </jgp-form-group>
        </jgp-query>
        <jgp-grid slot="3-1" _id="useForGrid" _single="true" _check="false"
                  _record_tools="[{'icon':'trash-o','tip':'编辑','fn':'editUseFor'},
                  {'icon':'trash-o','tip':'配置公众号','fn':'config'},
                  {'icon':'trash-o','tip':'生成微信连接','fn':'generateUrl'},
                  {'icon':'trash-o','tip':'删除','fn':'remove'}]"></jgp-grid>
    </jgp-div>
[/@JGP.body]

[@JGP.foot]
    <script>

        function closeCallback(result){
            if(result&&result.back){
                JGP.query('queryUseForForm').search();
            }
        }

        function editUseFor(result) {
            var useForId = result.back.record.id;
            var dialog = {
                'title': '编辑用途',
                'width': '500px',
                'height': '660px',
                'url': '/third/wx/wxConfigController/editUseFor/'+useForId,
                'callback': function (res) {
                    if (res) {
                        console.log(res);
                    }
                }
            };
            JGP.$dialog(dialog);
        }

        function config(result) {
            var useForId = result.back.record.id;
            var dialog = {
                'title': '配置公众号',
                'width': '500px',
                'height': '580px',
                'url': '/third/wx/wxConfigController/addConfig',
                'callback': function (res) {
                    if (res) {
                        console.log(useForId, res);
                        JGP.$post('/third/wx/wxConfigApiController/bindConfigToUseFor',
                                {useForId: useForId, configId: res})
                    }
                }
            };
            JGP.$dialog(dialog);
        }

        function generateUrl(result){
            var dialog = {
                'title': '生成微信链接',
                'width': '400px',
                'height': '100px',
                'url': '/third/wx/wxConfigController/generateUrl?useForId='+result.back.record.id,
                'callback': function (res) {}
            };
            JGP.$dialog(dialog);
        }

        function remove(result) {
            JGP.$confirm('是否确定删除:' + result.back.name + '?', function () {
                JGP.$post('/third/wx/wxConfigApiController/removeUseFor', {useForId: result.back.record.id}, function () {
                    location.reload();
                })
            })
        }
    </script>
[/@JGP.foot]